
public class Company {

	private int id = 0;
	private int size  = 2;
	private Worker[] workers = new Worker[size];  
	
	private void additionArray(){
		if (id >= size){
			size *=2;
		Worker [] boofer  = new Worker[size]; 
		for (int index=0; index < workers.length; index++)
			boofer[index]=workers[index];
		workers = boofer;
		}
	}
	
	public  void sortSalary(){
		for (int j = 0; j< id; j++)
			for (int i= j+1; i < id; i++){
				if(workers[i].calculate() > workers[j].calculate()){
					Worker boof = workers[j];
					workers[j] = workers[i];
					workers[i] = boof;
				}
			}
		
	}
	
	public  void sortId(){
		for (int j = 0; j< id; j++)
			for (int i= j+1; i < id; i++){
				if(workers[i].getId() < workers[j].getId()){
					Worker boof = workers[j];
					workers[j] = workers[i];
					workers[i] = boof;
				}
			}
		
	}
	
	public void sortName(){
		for (int j = 0; j < id; j++)
			for (int i= j+1; i < id; i++){
				if(workers[i].getName().compareTo(workers[j].getName()) < 0){
					Worker boof = workers[j];
					workers[j] = workers[i];
					workers[i] = boof;
				}
			}
	}
	
	public void add(String name, double hourRate){
		additionArray();
		workers[id] = new HourWorker(name, id, hourRate);
		id++;
	}

	public  Worker[] getWorkers(){
		return workers;
	}
	
	public void viewWorker(){
		for (int i = 0; i < id; i++)
			System.out.println("ID = "+ workers[i].getId()+
					 " Name=" + workers[i].getName() + 
		      " Hour worker=" + workers[i].calculate());
		
	}
	
	
	public void add(int hourRate, String name){
		additionArray();
		workers[id] = new MonthWorker(name,id, hourRate);
		id++;
	}
	
	public void add(String name){
		additionArray();
		workers[id] = new FixedWork(name, id);
		id++;
	}  
	
	public void delete(int id, int count){
		
		for (int index  = id; index < this.id-count; index++ ){
				workers[index] = workers[index+count];
				workers[index].setId(index);
				workers[index+count]=null;
		}
		this.id-=count;	
	}

}
